feat: pass invocation_state to edge condition calls#2305
Conversation
|
Issue: The PR introduces a public API change ( Suggestion: Consider adding the
|
|
Assessment: Comment Well-designed feature that cleanly extends the existing edge condition system with invocation_state context while maintaining full backwards compatibility. The protocol-based approach with Review Categories
The deadlock fix in |
I do not think i have permissions to add labels to this PR |
Add support for edge conditions that receive invocation_state, enabling conditional routing based on runtime context (feature flags, user roles, environment config) passed during graph invocation. Also fixes a deadlock in _compute_ready_nodes_for_resume() where conditional edges evaluating to False would block downstream nodes from ever becoming ready on interrupt/resume workflows. Resolves strands-agents#1346
- Cache inspect.signature() results via WeakKeyDictionary - Remove unused @runtime_checkable decorator - Gate serialization validation on session_manager presence - Add validation on deserialization path for symmetry - Move json import to module level - Add inline comments for short-circuit and cache behavior - Extract _make_graph() test helper, fix list->set type consistency
Cache the result of _is_context_condition() on each GraphEdge instance instead of a module-level WeakKeyDictionary. Simpler, no global state, and directly co-located with the edge that owns the condition.
97d4187 to
2d0cbd9
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Description
Add support for edge conditions that receive
invocation_state, enabling conditional routing based on runtime context (feature flags, user roles, environment config) passed duringgraph invocation.
Also fixes a deadlock in
_compute_ready_nodes_for_resume()where conditional edges evaluating toFalsewould block downstream nodes from ever becoming ready on interrupt/resume workflows.Session persistence of
invocation_stateWhen a
SessionManageris configured,invocation_stateis serialized alongside graph state so that resumed executions retain the same runtime context. This is validated as JSON-serializable on entry.Example: A graph with a feature-flag condition:
If the graph is interrupted and later resumed from session,
invocation_stateis restored soroute_if_premiumstill evaluates correctly without the caller needing to re-supply it.Public API Changes
GraphBuilder.add_edge()now accepts conditions with an extended signature via theEdgeConditionWithContextProtocol:Both signatures are supported indefinitely — no deprecation, no breaking changes.
Related Issues
Resolves #1346
Documentation PR
strands-agents/docs#847
Type of Change
New feature
Testing
How have you tested the change?
hatch run prepareChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.